﻿using System;

using DDDSample.Common.Validate;
using DDDSample.Domain.Model.Locations;

namespace DDDSample.Domain.Model.Carrier
{
	/// <summary>
	/// A carrier movement is a vessel voyage from one location to another.
	/// </summary>
	public class CarrierMovement : Entity<CarrierMovement>
	{
		private CarrierMovementId carrierMovementId;
		private Location from;
		private Location to;

		/// <summary>
		/// Constructor.
		/// </summary>
		/// <param name="carrierMovementId"></param>
		/// <param name="from"></param>
		/// <param name="to"></param>
		public CarrierMovement(CarrierMovementId carrierMovementId, Location from, Location to)
		{
			Validate.NotNull(carrierMovementId);
			Validate.NotNull(from);
			Validate.NotNull(to);
			this.carrierMovementId = carrierMovementId;
			this.from = from;
			this.to = to;
		}

		public CarrierMovementId CarrierMovementId
		{
			get { return this.carrierMovementId; }
		}

		public Location From
		{
			get { return this.from; }
		}

		public Location To
		{
			get { return this.to; }
		}

		public override bool SameIdentityAs(CarrierMovement other)
		{
			return this.carrierMovementId.SameValueAs(other.carrierMovementId);
		}

		public override bool Equals(object obj)
		{
			if (this == obj) return true;
			if (obj == null || GetType() != obj.GetType()) return false;

			CarrierMovement other = (CarrierMovement)obj;

			return SameIdentityAs(other);
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns>Hashcode of carrier movement id.</returns>
		public override int GetHashCode()
		{
			return this.carrierMovementId.GetHashCode();
		}

		private CarrierMovement()
		{
			// Needed by Hibernate
		}

		// Auto-generated surrogate key
		private long id;
	}
}
